<?php
/**
 * SelRoom Element for RoomBooking Component
 * 
 * @version 1.0
 * @package    Joomla
 * @subpackage RoomBooking
 * @copyright (C) 2011 Giovanni Marzulli
 * @license		GNU/GPL
 */

// No direct access
defined('_JEXEC') or die( 'Restricted access' );

JLoader::import('joomla.application.component.model');
JLoader::import('rooms',JPATH_ADMINISTRATOR.DS.'components'.DS.'com_roombooking'.DS.'models'); 

class JElementSelRoom extends JElement
{
        /**
         * Element name
         *
         * @access      protected
         * @var         string
         */
        var     $_name = 'SelRoom';
        
        
		/**
	 	 * construct a new HTML element
		 * @return JHTMLSelect object
	 	 */
        function fetchElement($name, $value, &$node, $control_name)
        {
        	$rooms_model = JModel::getInstance( 'rooms', 'RoomBookingModel' );
        	$rooms = $rooms_model->getData();
        	
        	$n = count( $rooms );
            for ($i = 0; $i < $n; $i++)
            {
            	$rooms[$i]->text = $rooms[$i]->id . ' - ' . $rooms[$i]->name;
            }
        	
        	 return JHTML::_('select.genericlist',  $rooms, ''.$control_name.'['.$name.']', 'class="inputbox"', 'id', 'text', $value, $control_name.$name );
        	 
        }
}